package br.com.uniban.mdb;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import br.com.uniban.util.SendMail;

/**
 * Message-Driven Bean implementation class for: EnviaEmailMDB
 * 
 */
@MessageDriven(activationConfig = {
		@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
		@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
		@ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/sendEmailQueue"),
		/*
		 * @ActivationConfigProperty(propertyName="ConnectionFactoryName",
		 * propertyValue="ConnectionFactory"),
		 */
		@ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable") })
public class SendEmailMDB implements MessageListener {

	public void onMessage(Message message) {
		MapMessage map = (MapMessage) message;
		
		try {
			String from = map.getString(SendEmailRemote.FROM);
			String to = map.getString(SendEmailRemote.TO);
			String subject = map.getString(SendEmailRemote.SUBJECT);
			String msg = map.getString(SendEmailRemote.MSG);
			
			SendMail email = new SendMail();
			
			email.sendMail(from, to, subject, msg);
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}

}
